package comWorld.social.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gjs.tools.utils.Utils;

import comWorld.social.SocialInfo;
import comWorld.social.VisitorCount;
import comWorld.user.UserInfo;

/**
 * Servlet implementation class FellowPageInit
 */
@WebServlet("/fellow")
public class FellowPageInit extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FellowPageInit() {
        super();
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int userId = (int) request.getAttribute("userId");
		VisitorCount visitorCount = VisitorCount.getLastVisitorCount(userId);
		visitorCount.add();
		request.setAttribute("visitorCount", visitorCount);
		
		SocialInfo socialInfo = (SocialInfo) request.getAttribute("socialInfo");
		List<UserInfo> fellows = socialInfo.getFellows();
		int[] be = Utils.paging(request, 10, fellows.size());
		request.setAttribute("fellows", fellows.subList(be[0], be[1]));
		request.getRequestDispatcher("/user/fellow.jsp").forward(request, response);
	}

}
